/**
 * Created by pro on 2018/7/30.
 */
$(function(){
    var ue = UE.getEditor('editor', {initialFrameHeight: 250});
    $('.btn-save').on('click', function(){
        $('[name="content"]').val(ue.getContent());
        var data = {
            title: $('.notice-title').val(),
            type: $('.notice-type').val(),
            content: $('.notice-content').val()
        };
        if (checkForm(data)) {
            sendAjax('/v1/manager/save/notice', 'post', {data:data}, function(json){
                var content = '<span>'+json.message+'</span>';
                if (json.status == 200) {
                    content += '<input type="hidden" class="jump-url" value="/manager/notice.html">';
                }
                $('#action-tip').find('.tip-content').append(content);
                $('#action-tip').modal('show');
            });
        }
    });

    $('#action-tip').on('hide.bs.modal', function(){
        if ($('.jump-url').val()) {
            location.href = $('.jump-url').val();
        }
    });
});

function checkForm(data) {
    if (!data.title) {
        $('#action-tip .modal-body .tip-content').text('请输入标题');
        $('#action-tip').modal('show');
        return false;
    }
    if (!data.type) {
        $('#action-tip .modal-body .tip-content').text('请选择类型');
        $('#action-tip').modal('show');
        return false;
    }
    if (!data.content) {
        $('#action-tip .modal-body .tip-content').text('请填写内容');
        $('#action-tip').modal('show');
        return false;
    }

    return true;
}